import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'community_project.settings')
django.setup()

from core.models import Announcement
from django.db import connection

print('检查MySQL数据库中的公告数据...')

# 检查数据库连接
with connection.cursor() as cursor:
    cursor.execute("SELECT DATABASE()")
    db_name = cursor.fetchone()[0]
    print(f'当前连接的数据库: {db_name}')

# 查询所有公告
announcements = Announcement.objects.all()
print(f'\n总共有 {announcements.count()} 条公告')

# 查看前10条公告
print('\n前10条公告:')
for ann in announcements[:10]:
    print(f'ID: {ann.announcement_id}, 标题: {ann.title}, 状态: {ann.status}')

# 检查公告180006
try:
    ann_180006 = Announcement.objects.get(announcement_id=180006)
    print(f'\n找到公告180006: {ann_180006.title}, 状态: {ann_180006.status}')
except Announcement.DoesNotExist:
    print('\n公告180006不存在')

# 检查状态为finalized的公告
finalized_announcements = Announcement.objects.filter(status='finalized')
print(f'\n状态为finalized的公告数量: {finalized_announcements.count()}')